---
import { getDatabase, schema } from "@/db";
import BaseLayout from "@/layouts/BaseLayout.astro";
import { eq } from "drizzle-orm";
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
import UserProfileView from "@/components/profile/UserProfileView.astro";
import ServerDirectoryBar from "@/components/profile/ServerDirectoryBar.astro";
const { owner: username } = Astro.params;
const db = getDatabase() as NodePgDatabase<typeof schema>;
const tab = Astro.url.searchParams.get("tab") || "overview";
// 1. Fetch User
const user = await db.query.users.findFirst({
where: eq(schema.users.username, username!),
});
// 2. If not a user, check if it's an organization
if (!user) {
const org = await db.query.organizations.findFirst({
where: eq(schema.organizations.name, username!),
});
if (org) {
return Astro.redirect(`/orgs/${org.name}`);
}
return Astro.redirect("/404");
}
---
<BaseLayout title={`${user.displayName || user.username} (${user.username})`}>
<!-- Server-wide discovery bar for all users and organizations -->
<ServerDirectoryBar currentUsername={user.username} />
<!-- GitHub-Authentic User Profile View -->
<UserProfileView user={user} tab={tab} />
</BaseLayout>